/*
 * cafe.js
 * Copyright (C) 2019 NRIET
 * Description: 
 * 		框架组件主入口JS
 * 		在此定义了CafeJS构造器
 * 		实现动态加载models方法
 */

;
(function(win, $, req, undefined) {

    'use strict';

    var CafeJS = null;
    //CafeJS对象预处理
    if (typeof CafeJS !== 'unedfined' ||
        CafeJS !== 'undefined' ||
        win.CafeJS !== 'undefined' ||
        $.CafeJS !== 'undefined') {
        CafeJS = function() {};
        win.CafeJS = CafeJS;
    }

    //CafeJS构造方法
    var CFJS = function(settings) {
        var options = {};
        this.config = $.extend({}, options, settings);
        this.init();
    };
    //CafeJS PROTOTYPE'S
    CFJS.prototype = {
        VERSION: "V1.0",
        init: function() {
            this.getConfig();
        },
        getConfig: function() {
            $.getScript("/static/widgets/cafejs/cafe-config.js", function() {
                CafeJS.initConfig(function() {});
            });
        },
    };

    var cfJS = new CFJS();

    //模块动态加载
    CafeJS.models = function(mods, call) {
        if (mods && mods.length > 0) {
            call = typeof call !== 'function' ? function() {} : call;
            var deps = false;
            if (CafeJS.Jsdep) {
                $.each(mods, function(key, mod) {
                    var dps = CafeJS.Jsdep[mod];
                    if (dps) {
                        req(dps, null, function(err) {
                            var msg = err.name + ': ' + err.message + ',' + err.requireModules;
                            msg += ',注入失败,请检查!';
                            console.error(msg);
                        });
                    }
                });
            }
            setTimeout(function() {
                req(mods, call, function(err) {
                    var msg = err.name + ': ' + err.message + ',' + err.requireModules;
                    msg += '模块加载,请检查此模块!';
                    console.error(msg);
                });
            }, 500);
        }
    };
})(window, jQuery, require, {});